package com.mach.platform.repository;

import com.mach.platform.domain.iot.IotDevParams;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface IotDevParamsRepo extends BaseRepository<IotDevParams> {

    @Query(value = "select name, value from iot_dev_prop where dev_id = ?1", nativeQuery = true)
    List<Map> findByDevId(Long id);

    List<IotDevParams> findAllByDevIdIn(List<Integer> devId);

    List<IotDevParams> findAllByDevId(Integer devId);

    /**
     * 查询设备的负载范围
     * @param id 设备id
     * @return
     */
    @Query(value = "select * from iot_dev_prop where dev_id = ?1 and name = 'loadRange'", nativeQuery = true)
    IotDevParams findLoadRangeByDevId(Integer id);

    @Modifying
    @Query(value = "delete from iot_dev_prop where dev_id in (?1)", nativeQuery = true)
    int deleteByDevIds(List<Long> devIds);

}
